import { h } from 'vue'
import { NIcon } from 'naive-ui'
import {
  DashboardOutlined as dashboard,
  PersonOutlineFilled as person,
  LockOutlined as lock,
  SettingsFilled as setting,
  RemoveRedEyeOutlined as eye,
  MenuFilled as system
} from '@vicons/material'


export function generatorMenu(routeMap: Array<any>) {
  return filterRouter(routeMap).map((item) => {
    const currentMenu: any = {
      label: item.meta?.title,
      key: item.name,
      icon: constantRouterIcon[item.meta.icon] || null
    }
    
    if(item.children?.length > 0) {
      currentMenu.children = generatorMenu(item.children)
    }
    return currentMenu
  })
}



// 菜单图标映射表
export const constantRouterIcon = {
  person: renderIcon(person),
  eye: renderIcon(eye),
  system: renderIcon(system)
};

/**
 * 渲染图标
 * @param icon 
 */
 export function renderIcon(icon: any) {
  return () => h(NIcon, null, { default: () => h(icon) })
}


/**
 * 过滤掉不显示在菜单的路由
 * @param routerMap 
 * @returns 
 */
export function filterRouter(routerMap: Array<any>) {
  return routerMap.filter((item) => {
    return (
      (item.hidden || false) != true &&
      !['/:path(.*)', '/'].includes(item.path)
    )
  })
}

// export function isRootRouter(item) {
//   return item.meta?.alwaysShow != true && item.children?.length === 1
// }

